package com.starview.star.compiler.wff;

import com.starview.platform.data.type.Location;
import com.starview.star.compiler.ast.IAbstract;
import com.starview.star.compiler.standard.StandardNames;
import com.starview.star.compiler.util.PrettyPrintDisplay;
import com.starview.star.compiler.wff.WffOp.applyMode;

@SuppressWarnings("serial")
public class WffAndCnd implements WffCond
{
  private final WffCond left, right;

  public WffAndCnd(WffCond left, WffCond right)
  {
    this.left = left;
    this.right = right;
  }

  @Override
  public applyMode satisfied(IAbstract env[], Location loc, WffEngine engine)
  {
    applyMode mode = left.satisfied(env, loc, engine);

    if (mode == applyMode.validates)
      mode = right.satisfied(env, loc, engine);
    return mode;
  }

  @Override
  public void prettyPrint(PrettyPrintDisplay disp)
  {
    left.prettyPrint(disp);
    disp.append(" ");
    disp.append(StandardNames.WFF_AND);
    disp.append(" ");
    right.prettyPrint(disp);
  }

  @Override
  public String toString()
  {
    return PrettyPrintDisplay.toString(this);
  }
}
